$(document).ready(function() {	
	$('.tipsy').tipsy({gravity: 'w'});// nw | n | ne | w | e | sw | s | se --- http://onehackoranother.com/projects/jquery/tipsy/
	$("#frmCreate").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,rules: {
			pname:{
				required				: true,
				minlength				: 5
			},
			pimage: {
				validateImgFormat		: true,
				validateImgSize			: true
			},
			pmusic: {
				validateObjectFormat	: true
			},
			pcontent: {
				validateContentRequired	: true,
				validateContentMinlength: true
			}
		},
		messages: {			
			pname:{
				required				: name_required,
				minlength				: name_minlength
			},
			pimage: {
				validateImgFormat		: image_format,
				validateImgSize			: image_size
			},
			pmusic: {
				validateObjectFormat	: music_format
			},
			pcontent: {
				validateContentRequired	: content_required,
				validateContentMinlength: content_minlength
			}
		},
		errorPlacement: function(label, element) {
			var id = element.attr('id');	
			if(id == "pimage") {
				label.insertAfter($('#aimage'));
			} else if(id == "pmusic") {
				label.insertAfter($('#amusic'));			
			} else if(id == "pcontent") {			
				label.insertAfter($('#pcontent___Frame'));
			} else {
				label.insertAfter($('#' + id));			
			}
			
		}				 
	});	
	$.validator.addMethod('validateImgFormat', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return true;
		}
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validateImgSize', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return true;
		}
		return validateImgSize("pimage");
	});
	$.validator.addMethod('validateObjectFormat', function() {
		var strLinkMusic = $('#pmusic').val();
		if(strLinkMusic == "") {
			return true;
		}
		return validateObjectFlash(strLinkMusic);
	});
	$.validator.addMethod('validateContentRequired',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ), 1);		
		if(strContent == '')
			return false;		
		return true;												 
	});
	$.validator.addMethod('validateContentMinlength',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ), 1);		
		if(strContent != '' && strContent.length < 20)
			return false;		
		return true;												 
	});
});